home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / eiffel / eiffel_p.z / eiffel_p / ep / Merge.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-09  |  3.3 KB  |  179 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <limits.h>
  4. #include <sys/param.h>
  5.  
  6. #define TRUE        1
  7. #define FALSE        0
  8.  
  9. #define PERMS         0644
  10. #define ERR_LINE     1024    
  11. #define IN_LINE     1024
  12.  
  13. #define ERROR        1
  14. #define WARNING        2
  15. #define INFORMATION    3
  16. #define NOTE        4
  17. #define FATAL        5
  18. #define REP_RES        6
  19. #define UNKOWN_CLASS    9
  20. #define UNKOWN_ERR    99    
  21.  
  22. typedef struct {
  23.     int line;
  24.     int col;
  25.     int type;
  26. } t_errline;
  27.     
  28. extern char in_file[MAXPATHLEN],
  29.              lst_file[MAXPATHLEN],
  30.              err_file[MAXPATHLEN],
  31.              *command;
  32.  
  33. char last_line;
  34.  
  35.  
  36. void write_err(fp)
  37. FILE *fp;
  38. {
  39.         if ((fp = fopen(err_file, "w")) == NULL ) {
  40.           fprintf(stderr, "%s: can't open %s\n", command, err_file);
  41.           exit(1);
  42.         }
  43.         else {
  44.           WriteMessages(fp);
  45.       fclose(fp);
  46.     }
  47. }
  48.  
  49. void cp_lines(from, to, n)
  50. FILE *from, *to;
  51. int n;
  52. {
  53.     int i = 0;
  54.     char buf[IN_LINE];
  55.  
  56.     while (i++ < n && !last_line) {
  57.       if (fgets(buf, IN_LINE, from) == NULL) {
  58.         last_line = TRUE;
  59.       }
  60.       if (!last_line)
  61.         if (fputs(buf, to) == EOF) {
  62.           fprintf(stderr,"%s: internal error, please report: cp_lines(), fputs()\n", command);
  63.           exit(1);
  64.         }
  65.     }
  66. }
  67.      
  68.  
  69. void analyse_line(buf, info)
  70. char *buf;
  71. t_errline *info;
  72. {
  73.     char type[256];
  74.  
  75.     if(sscanf(buf,"  %d, %d:  %s ", &info->line, &info->col, type) == 3) {
  76.       switch (type[0]) {
  77.         case 'E' : info->type = ERROR; break;
  78.         case 'W' : info->type = WARNING; break;
  79.         case 'I' : info->type = INFORMATION; break;
  80.         case 'N' : info->type = NOTE; break;
  81.         case 'F' : info->type = FATAL; break;
  82.         case 'R' : info->type = REP_RES; break;
  83.         default  : info->type = UNKOWN_CLASS;
  84.       }
  85.     }
  86.     else {
  87.       fprintf(stderr, "sscanf error\n");
  88.       info->type = UNKOWN_ERR;
  89.     }
  90. }
  91.  
  92. void put_line(fp, buf) 
  93. FILE *fp;
  94. char *buf;
  95. {
  96.     if (fputs(buf, fp) == EOF) {
  97.       fprintf(stderr,"%s: internal error, please report: put_err_line(), fputs()\n", command);
  98.       exit(1);
  99.      }
  100. }
  101.  
  102.  
  103. void make_ptr(buf, col)
  104. char *buf;
  105. int col;
  106. {
  107.     int i;
  108.  
  109.     bzero(buf, IN_LINE);
  110.     for(i = 0; i <= (col-2); i++) {
  111.       buf[i] = ' ';
  112.     }
  113.     buf[col-1] = '^';
  114.     buf[col] = '\n';
  115. }
  116.  
  117. void put_err_line(fp, buf, info) 
  118. FILE *fp;
  119. char *buf;
  120. t_errline *info;
  121. {
  122.     char ptr_buf[IN_LINE];
  123.     
  124.     switch (info->type) {
  125.       case (ERROR)         : 
  126.       case (WARNING)    :
  127.         make_ptr(ptr_buf, info->col);
  128.         put_line(fp, ptr_buf);
  129.         put_line(fp, buf);
  130.         break;
  131.       case (UNKOWN_ERR)    :
  132.       default : put_line(fp, buf);
  133.     }
  134. }
  135.     
  136.         
  137.  
  138.     
  139. void gen_lst() 
  140. {
  141.     char err_buf[ERR_LINE],
  142.               in_buf[IN_LINE];
  143.     FILE *in_fp, *lst_fp, *err_fp;
  144.     t_errline line_info;    
  145.     int last = 0;
  146.  
  147.     write_err(err_fp);
  148.     last_line = FALSE;
  149.     if ((in_fp = fopen(in_file, "r")) == NULL) {
  150.       fprintf(stderr, "%s: can't open %s\n", command, in_file);
  151.       exit(1);
  152.     }
  153.     if ((lst_fp = fopen(lst_file, "w")) == NULL) {
  154.       fprintf(stderr, "%s: can't open %s\n", command, lst_file);
  155.       exit(1);
  156.     }
  157.     if ((err_fp = fopen(err_file, "r")) == NULL) {
  158.       fprintf(stderr, "%s: can't open %s\n", command, err_file);
  159.       exit(1);
  160.     }
  161.     while ((fgets(err_buf, ERR_LINE, err_fp)) != NULL ) {
  162.       analyse_line(err_buf, &line_info);
  163.       if (line_info.line == last) {
  164.         put_err_line(lst_fp, err_buf, &line_info); 
  165.       }
  166.       else {
  167.         cp_lines(in_fp, lst_fp, line_info.line - last);
  168.         last = line_info.line;
  169.         put_err_line(lst_fp, err_buf, &line_info); 
  170.       }
  171.     }
  172.     cp_lines(in_fp, lst_fp, INT_MAX);
  173.  
  174.     fclose(in_fp);
  175.     fclose(lst_fp);
  176.     fclose(err_fp);
  177.     unlink(err_file);
  178. }
  179.